namespace LS.UGFUnits
{
    using Unity.VisualScripting;
    
    [UnitShortTitle("Config")]
    [UnitSurtitle("Get Bool")]
    public sealed class GetBoolConfig: ConfigUnit
    {
        [DoNotSerialize]
        [PortLabelHidden]
        public ValueInput Key { get; private set; }
        
        [DoNotSerialize]
        [PortLabelHidden]
        public ValueOutput Value { get; private set; }

        protected override void Definition()
        {
            base.Definition();
            Key = ValueInput<string>(nameof(Key), string.Empty);
            Value = ValueOutput<bool>(nameof(Value));
            Requirement(Key, Value);
        }

        protected override ControlOutput In(Flow flow)
        {
            string path = flow.GetValue<string>(Key);
            bool value = Target?.GetBool(path) ?? false;
            flow.SetValue(Value, value);
            return base.In(flow);
        }
    }
}